/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.faces.bean.ManagedBean;

/**
 *
 * @author jzajaczek
 */
@ManagedBean(name="loginBean")

public class loginBean implements Serializable {
    private String name;
    private String password;
         
    private dbconnectBean con = new dbconnectBean();
    
    public String login() throws SQLException, ClassNotFoundException {
        Boolean ok = false;
        java.sql.Statement stm = con.dbConnection().createStatement();
        ResultSet rs = stm.executeQuery("select * from users");
        
        while (rs.next()) {
            String dbname = rs.getString("name");
            String dbpassword = rs.getString("pass");
            
            
            if (name.equals(dbname)&& password.equals(dbpassword)) {
                ok = true;
            }
            else {
                ok = false;;
            }
        }

        if (ok == true) {
            return "/view/MainView.xhtml";    
        } else {
            return "/view/error.xhtml";
        }
    }
    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return the con
     */
    public dbconnectBean getCon() {
        return con;
    }

    /**
     * @param con the con to set
     */
    public void setCon(dbconnectBean con) {
        this.con = con;
    }
}